diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-09 17:18:46 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | f699802b837d7d9fcf150ff2bf00cd3c5475c87a (patch) | |
| tree | 6c96a140193e7386b454b6d444058a99a0e07454 /src/pages/article/[slug].tsx | |
| parent | bd9c9ae7e2ae973969569dd434836de9f38b07d4 (diff) | |
refactor(components): rewrite CommentsList component
* use ApprovedCommentProps to make CommentData type
* add the author name of the parent on reply form heading
* add tests
Diffstat (limited to 'src/pages/article/[slug].tsx')
| -rw-r--r-- | src/pages/article/[slug].tsx | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx index 449af8d..d35541a 100644 --- a/src/pages/article/[slug].tsx +++ b/src/pages/article/[slug].tsx @@ -17,6 +17,7 @@ import { Spinner, type MetaItemData, Time, + type CommentData, } from '../../components'; import { getAllArticlesSlugs, @@ -64,6 +65,19 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({ contentId: article?.id, fallback: comments, }); + + const getComments = (data?: SingleComment[]) => + data?.map((comment): CommentData => { + return { + author: comment.meta.author, + content: comment.content, + id: comment.id, + isApproved: comment.approved, + publicationDate: comment.meta.date, + replies: getComments(comment.replies), + }; + }); + const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({ title: article?.title ?? '', url: `${ROUTES.ARTICLE}/${slug}`, @@ -313,7 +327,7 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({ bodyClassName={styles.body} breadcrumb={breadcrumbItems} breadcrumbSchema={breadcrumbSchema} - comments={commentsData} + comments={getComments(commentsData)} footerMeta={footerMeta} headerMeta={filteredHeaderMeta} id={id as number} |
